package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.JOptionPane;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * This class get the raw inventory from the DB 
 * @author Gabi Revah
 * @author Aviad Almog
 */ 
public class MessageRawInv {
	private ConnectionToClient client ;
	private String[] str; 
/**
 * Constructor of this class 
 * @param str
 * @param client
 */
	public MessageRawInv(String[] str, ConnectionToClient client) {
		this.client= client ;
		this.str= str; 
	
	}
	
	/**
	 * This method gets raw inventory from the DB 
	 * @throws SQLException
	 * @throws IOException
	 */
public void RawInv() throws SQLException, IOException{
		
	
		SQLConnection sc = new SQLConnection();
		java.sql.PreparedStatement ps = sc.getConnection().prepareStatement("SELECT * FROM db.rawmaterial");
		ResultSet RawInvRes= ps.executeQuery();
		ArrayList<Object> ri=new ArrayList<Object>();
		ri.add("RawInv");
		while (RawInvRes.next())
		{
			ri.add(RawInvRes.getString(1));
			ri.add(RawInvRes.getString(2));
			ri.add(RawInvRes.getInt(3));
			ri.add(RawInvRes.getInt(4));
			ri.add(RawInvRes.getInt(5));
		}
		client.sendToClient(ri);
	}

}
